package com.von.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.von.entity.DictionaryGroup;
import com.von.param.DictionaryGroupParam;
import com.von.result.R;
import com.von.service.IDictionaryGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 字典-组 前端控制器
 * </p>
 *
 * @author xiaosai
 * @since 2021-07-09
 */
@RestController
@RequestMapping("/dictionaryGroup")
public class DictionaryGroupController {

    /**
     * @apiDefine dictionaryGroup 字典组
     */

    @Autowired
    private IDictionaryGroupService iDictionaryGroupService;

    /**
     * @api {post} /dictionaryGroup/list 分页查询
     * @apiGroup dictionaryGroup
     * @apiParam {Integer} pageNum 当前页
     * @apiParam {Integer} pageSize 页面条数
     * @apiParamExample {json} Request-Example:
     * {
     *     "pageNum":1,
     *     "pageSize":10
     * }
     * @apiSuccess {String} name 字典组名
     * @apiSuccess {String} remark 备注
     * @apiSuccessExample {json} Success-Response:
     * {
     *     "code": 0,
     *     "data": {
     *         "records": [
     *             {
     *                 "id": 2,
     *                 "name": "字典组名",
     *                 "remark": “备注”,
     *                 "createTime": "创建时间",
     *                 "updateTime": "更新时间",
     *                 "status": 0,
     *                 "isdel": 0
     *             }
     *         ],
     *         "total": 3,
     *         "size": 1,
     *         "current": 2,
     *         "orders": [],
     *         "optimizeCountSql": true,
     *         "hitCount": false,
     *         "countId": null,
     *         "maxLimit": null,
     *         "searchCount": true,
     *         "pages": 3
     *     },
     *     "msg": "执行成功"
     * }
     */
    @PostMapping("/list")
    public R<Page<DictionaryGroup>> list(@RequestBody DictionaryGroupParam dictionaryGroupParam){
        return iDictionaryGroupService.list(dictionaryGroupParam);
    }

    /**
     * @api {post} /dictionaryGroup/add 添加
     * @apiGroup dictionaryGroup
     * @apiParam {String} name 字典组名[必填]
     * @apiParam {String} remark 备注
     * @apiParamExample {json} Request-Example:
     * {
     *     "name":"dataDemo",
     *     "remark":"dataDemo"
     * }
     * @apiSuccessExample {json} Success-Response:
     * {
     *     "code":0，
     *     “msg”:"执行成功"，
     *     “data”:null
     * }
     */
    @PostMapping("/add")
    public R<String> add(@RequestBody DictionaryGroup dictionaryGroup){
        return iDictionaryGroupService.add(dictionaryGroup);
    }

    /**
     * @api {post} /dictionaryGroup/update 更新
     * @apiGroup dictionaryGroup
     * @apiParam {Integer} id [必填]
     * @apiParam {String} name 字典组名[必填]
     * @apiParam {String} remark 备注
     * @apiParamExample {json} Request-Example:
     * {
     *     "id":1,
     *     "name":"dataDemo",
     *     "remark":"dataDemo"
     * }
     * @apiSuccessExample {json} Success-Response:
     * {
     *     "code":0，
     *     “msg”:"执行成功"，
     *     “data”:null
     * }
     */
    @PostMapping("/update")
    public R<String> update(@RequestBody DictionaryGroupParam dictionaryGroupParam){
        return iDictionaryGroupService.update(dictionaryGroupParam);
    }

    /**
     * @api {get} /dictionaryGroup/del 删除
     * @apiGroup dictionaryGroup
     * @apiParam {Integer} id[必填]
     * @apiSuccessExample {json} Success-Response:
     * {
     *     "code":0，
     *     “msg”:"执行成功"，
     *     “data”:null
     * }
     */
    @GetMapping("/del")
    public R<String> del(Integer id){
        return iDictionaryGroupService.del(id);
    }
}
